//
//  YJBTradeDetailCell.m
//  YunJiaBaoFirst
//
//  Created by 腾云小白龍 on 16/7/30.
//  Copyright © 2016年 腾云小白龍. All rights reserved.
//

#import "YJBTradeDetailCell.h"
#import "NSDate+DateTools.h"
@interface YJBTradeDetailCell()

@property (strong, nonatomic) UILabel * timeLabel;
@property (strong, nonatomic) UILabel * moneyLabel;
@property (strong, nonatomic) UILabel * nowHandLabel;
@property (strong, nonatomic) UILabel * changeLabel;
@property (strong, nonatomic) UILabel * stateLabel;

@end

@implementation YJBTradeDetailCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString * ID = @"TradeDetailCell";
    
    YJBTradeDetailCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil) {
        cell = [[YJBTradeDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if(self) {
        self.backgroundColor = DEFAULT_COLOR;
        
        UILabel * timeLabel = [[UILabel alloc] init];
        self.timeLabel = timeLabel;
        self.timeLabel.textColor = [UIColor blackColor];
        self.timeLabel.font = [UIFont systemFontOfSize:14];
        self.timeLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:timeLabel];
        
        UILabel * moneyLabel = [[UILabel alloc] init];
        self.moneyLabel = moneyLabel;
        self.moneyLabel.textColor = [UIColor blackColor];
        self.moneyLabel.font = [UIFont systemFontOfSize:14];
        self.moneyLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:moneyLabel];
        
        UILabel * nowHandLabel = [[UILabel alloc] init];
        self.nowHandLabel = nowHandLabel;
        self.nowHandLabel.textColor = [UIColor blackColor];
        self.nowHandLabel.font = [UIFont systemFontOfSize:14];
        self.nowHandLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:nowHandLabel];
        
        UILabel * changeLabel = [[UILabel alloc] init];
        self.changeLabel = changeLabel;
        self.changeLabel.textColor = [UIColor blackColor];
        self.changeLabel.font = [UIFont systemFontOfSize:14];
        self.changeLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:changeLabel];
        
        UILabel * stateLabel = [[UILabel alloc] init];
        self.stateLabel = stateLabel;
        self.stateLabel.textColor = [UIColor blackColor];
        self.stateLabel.font = [UIFont systemFontOfSize:14];
        self.stateLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:stateLabel];
        
        timeLabel.frame     = CGRectMake(0, 0, 2 * SCREEN_WIDTH / 9, 44);
        moneyLabel.frame    = CGRectMake(2 * SCREEN_WIDTH / 9, 0, 2 * SCREEN_WIDTH / 9, 44);
        nowHandLabel.frame  = CGRectMake(4 * SCREEN_WIDTH / 9, 0, SCREEN_WIDTH / 6, 44);
        changeLabel.frame   = CGRectMake(CGRectGetMaxX(nowHandLabel.frame), 0, SCREEN_WIDTH / 6, 44);
        stateLabel.frame    = CGRectMake(CGRectGetMaxX(changeLabel.frame), 0, 2 * SCREEN_WIDTH / 9, 44);

    }
    
    return self;
}


-(void)setTradeDealRecodeModel:(YJBTradeDealRecodeModel *)tradeDealRecodeModel{
    
    _tradeDealRecodeModel = tradeDealRecodeModel;
    

    NSInteger timeFloat = [tradeDealRecodeModel.time integerValue]/1000;
    
    NSDate *currentDate = [NSDate date];
    NSString *curDateStr = [NSString stringWithFormat:@"%ld",(long)[currentDate timeIntervalSince1970]];
    NSInteger currDate = [curDateStr integerValue];
    
    NSInteger differentValue = self.systemTime/1000 - currDate;
    timeFloat = timeFloat - differentValue ;
    NSDate * dateCreate = [NSDate dateWithTimeIntervalSince1970:timeFloat];
    self.timeLabel.text = [dateCreate timeAgoSinceNow];
//    self.timeLabel.text = [NSDate timeAgoSinceDate:dateCreate];

    

    self.moneyLabel.text  = [NSString stringWithFormat:@"%.2f",tradeDealRecodeModel.price];
    
    self.nowHandLabel.text  = [NSString stringWithFormat:@"%ld",tradeDealRecodeModel.quantity];
    
    self.changeLabel.text  = [NSString stringWithFormat:@"%ld", tradeDealRecodeModel.disparity];
    
    NSInteger type = tradeDealRecodeModel.type;
    if(type == 0) {
        self.stateLabel.text = @"看涨";
    } else if(type == 1) {
        self.stateLabel.text = @"看跌";
    } else if(type == 2) {
        self.stateLabel.text = @"看涨";
    } else {
        self.stateLabel.text = @"看跌";
    }

    
}

@end
